﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using LibNiconico.NiconicoApi.Internal;
using LibNiconico.NiconicoApi.Extentions;

namespace LibNiconico.NiconicoApi.Videos.ThumbInfo
{
    /// <summary>
    /// ニコニコ動画タグ群
    /// </summary>
    public sealed class NicoVideoTags
    {
        /// <summary>
        /// 国
        /// </summary>
        public string Domein
        {
            get;
            internal set;
        }

        /// <summary>
        /// タグリスト
        /// </summary>
        public IEnumerable<NicoVideoTag> Value
        {
            get;
            internal set;

        }

        internal NicoVideoTags()
        {
            Domein = "";


        }

        internal static IEnumerable<NicoVideoTags> Parse(XElement element)
        {
            
            if (element == null) return null;
            return from tagsEnum in element.Descendants("tags")
                   select new NicoVideoTags
                   {
                       Domein = XElementExtention.GetAttributeAsString(tagsEnum, "domain"),

                       Value = from tags in tagsEnum.Descendants("tag")
                               select new NicoVideoTag
                               {
                                   Category = XElementExtention.GetAttributeAsBool(tags, "category"),
                                   Lock = XElementExtention.GetAttributeAsBool(tags, "lock"),
                                   Tag = tags.Value

                               }
                   };

        }


    }
}
